package com.wasp.collector.data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class RequestContext implements Serializable{

	private static final long serialVersionUID = 5394542452504270285L;
	private String url;
	//额外的数据
	private Map<String,Object> context;
	
	public RequestContext(String url,Map<String,Object> maps){
		this.url = url;
		this.context = maps;
	}
	public Map<String,Object> getContext() {
		return context;
	}
	public void setContext(Map<String,Object> context) {
		this.context = context;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
	
	public static RequestContext cloneRequest(RequestContext context){
		RequestContext c = new RequestContext(context.getUrl(), context.getContext());
		return c;
	}
	
	public static List<String> getUrls(List<RequestContext> list){
		if(list == null){
			return null;
		}
		List<String> urls = list.stream().
				            collect(() -> new ArrayList<String>(),
				                    (tmpurls, item) -> tmpurls.add(item.getUrl()),
				                    (list1, list2) -> list1.addAll(list2));
		return urls;
	}
	/*public static void main(String[] args) {
		List<RequestContext> list = Lists.newArrayList();
		RequestContext c1 = new RequestContext("1",null);
		RequestContext c2 = new RequestContext("2",null);
		list.add(c1);
		list.add(c2);
		List<String> us= RequestContext.getUrls(list);
		us.stream().forEach(item->System.out.println(item));
	}*/
}